package com.example.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.pojo.Pet;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author Lexin Huang
 */
@Mapper
@Repository
public interface PetMapper extends BaseMapper<Pet> {

    /**
     * 查询封装 PetVo 对象的方法
     * @param userId 用户id
     * @return 宠物集合
     */
    @Results(id = "petMap", value = {
            @Result(column = "id", property = "id", javaType = Integer.class, id = true),
            @Result(column = "pet_portrait_path", property = "portraitPath", javaType = String.class),
            @Result(column = "pet_name", property = "name", javaType = String.class),
            @Result(column = "pet_breed", property = "breed", javaType = String.class),
            @Result(column = "pet_introduction", property = "introduction", javaType = String.class),
            @Result(column = "pet_is_overt", property = "overt", javaType = Boolean.class),
            @Result(column = "user_id", property = "userId", javaType = Integer.class)
    })
    @Select("Select * from pet where user_id = #{userId}")
    List<Pet> selectByUserId(@Param("userId") Integer userId);

    @Deprecated
    @ResultMap(value = "petMap")
    @Select("Select * from pet where id = #{petId} and user_id = #{userId}")
    Pet selectPetInfoById(@Param("userId") Integer userId, @Param("petId")Integer petId);

    /**
     * 查询指定名称的宠物
     * @param petName 宠物名称
     * @return 宠物对象
     */
    @ResultMap(value = "petMap")
    @Select("Select * from pet where pet_name = #{petName}")
    Pet getByPetName(@Param("petName") String petName);
}
